package org.yx.service.smat.view_material_sn_to_print_label;

import com.xiaoleilu.hutool.map.MapUtil;
import com.xiaoleilu.hutool.util.StrUtil;
import org.springframework.util.StreamUtils;
import org.yx.utils.BaseService;
import yxmes.tools.FineReportUtil;

import java.util.HashMap;
import java.util.Map;

/**
 * 调出原材料的标签打印
 * @author zxw
 * @since 2023/03/14
**/
public class SmatViewMaterialSnToPrintLabelService extends BaseService {
	public SmatViewMaterialSnToPrintLabelOut viewMaterialSnToPrintLabel(SmatViewMaterialSnToPrintLabelIn in) throws Exception {
		Map<String, Object> mapParm = new HashMap<String, Object>();
		String[] msns = StrUtil.removeSuffix(in.getMsns(),",").split(",");
		String msn = StrUtil.join("','", (Object[]) msns);
		msn = StrUtil.addPrefixIfNot(msn,"'");
		msn = StrUtil.addSuffixIfNot(msn,"'");
		mapParm.put("msn", msn);
		mapParm.put("orgCode",in.getUserOrgCode());

		SmatViewMaterialSnToPrintLabelOut out = new SmatViewMaterialSnToPrintLabelOut();
		out.setFileName(FineReportUtil.printDataToPdf(mapParm, in.getUserOrgCode() + "_material_label.cpt").getName());

		return out;
	}
}